#include<bits/stdc++.h>
#define uint unsigned int
#define ll long long
#define ull unsigned long long
#define mid ((l+r)>>1)
#define ls(x) tree[x].son[0]
#define rs(x) tree[x].son[1]
#define File(xxx) freopen(xxx".in","r",stdin),freopen(xxx".out","w",stdout)
using namespace std;
namespace IO{
    char buff[1<<21],*p1=buff,*p2=buff;
    char getch(){
        return p1==p2&&(p2=((p1=buff)+fread(buff,1,1<<21,stdin)),p1==p2)?EOF:*p1++;
    }
    template<typename T>
    void read(T &x){
        char ch=getch();int fl=1;x=0;
        while(ch>'9'||ch<'0'){if(ch=='-')fl=-1;ch=getch();}
        while(ch<='9'&&ch>='0'){x=x*10+ch-48;ch=getch();}
        x*=fl;
    }
    template<typename T,typename ...Args>
    void read(T &x,Args& ...args){
        read(x);read(args...);
    }
    char obuf[1<<21],*p3=obuf;
    void putch(char ch){
        if(p3-obuf<(1<<21))*p3++=ch;
        else fwrite(obuf,p3-obuf,1,stdout),p3=obuf,*p3++=ch;
    }
    void pc(const char *s){
    	while(*s)putch(*s),s++;
    }
    char ch[100];
    template<typename T>
    void write(T x){
        if(!x)return putch('0');
        if(x<0)putch('-'),x*=-1;
        int top=0;
        while(x)ch[++top]=x%10+48,x/=10;
        while(top)putch(ch[top]),top--;
    }
    template<typename T,typename ...Args>
    void write(T x,Args ...args){
        write(x),putch(' '),write(args...);
    }
    void flush(){fwrite(obuf,p3-obuf,1,stdout);p3=obuf;}
}
using namespace IO;
const int N=2e5+5;
int n,q;
ll sum[N];
int Fa[18][N],fa[N],dep[N],siz[N],son[N],dfn[N],id[N],top[N],tot;
vector<pair<int,int>>to[N];
void dfs1(int x,int p){
	fa[x]=p;
	dep[x]=dep[p]+1;
	siz[x]=1;
	for(auto E:to[x]){
		int y=E.first,w=E.second;
		if(y==p)continue;
		sum[y]=sum[x]+w;
		dfs1(y,x);
		siz[x]+=siz[y];
		if(siz[y]>siz[son[x]])son[x]=y;
	}
}
void dfs2(int x,int Top){
	id[dfn[x]=++tot]=x;
	top[x]=Top;
	if(son[x])dfs2(son[x],Top);
	for(auto E:to[x]){
		int y=E.first,w=E.second;
		if(y==fa[x])continue;
		if(y==son[x])continue;
		dfs2(y,y);
	}
}

int rt[N];
struct node{
	int maxn;
	int son[2];
}tree[N<<5];
void modify(int &x,int y,int l,int r,int w,int v){
	if(!x)x=++tot;
	tree[x].maxn=max(tree[y].maxn,v);
	if(l==r)return;
	if(w<=mid)modify(ls(x),ls(y),l,mid,w,v),rs(x)=rs(y);
	else modify(rs(x),rs(y),mid+1,r,w,v),ls(x)=ls(y);
}
bool query(int x,int l,int r,int L,int R,int val){
	if(!x)return 0;
	if(tree[x].maxn<val)return 0;
	if(L<=l&&r<=R)return 1;
	if(R<=mid)return query(ls(x),l,mid,L,R,val);
	else if(L>mid)return query(rs(x),mid+1,r,L,R,val);
	else{
		if(query(ls(x),l,mid,L,R,val))return 1;
		if(query(rs(x),mid+1,r,L,R,val))return 1;
		return 0;
	}
}
inline int lca(int x,int y){
	while(top[x]!=top[y]){
		if(dep[top[x]]>dep[top[y]])x=fa[top[x]];
		else y=fa[top[y]];
	}
	if(dep[x]<dep[y])return x;
	else return y;
}
int LOG[N],st[18][N];
inline int Range_lca(int l,int r){
	int len=LOG[r-l+1];
	return lca(st[len][l],st[len][r-(1<<len)+1]);
}
signed main(){
	File("memory");
	read(n,q);
	for(int i=1;i<n;i++){
		int x,y,w;
		read(x,y,w);
		to[x].push_back({y,w});
		to[y].push_back({x,w});
	}
	dfs1(1,0);
	dfs2(1,1);
	tot=0;
	for(int i=1;i<=n;i++)
		modify(rt[i],rt[i-1],1,n,dfn[i],i);
	for(int i=2;i<=n;i++)
		LOG[i]=LOG[i>>1]+1;
	for(int i=1;i<=n;i++)
		st[0][i]=i;
	for(int i=1;i<18;i++)
		for(int j=1;j+(1<<i)-1<=n;j++)
			st[i][j]=lca(st[i-1][j],st[i-1][j+(1<<(i-1))]);
	for(int i=1;i<=n;i++)
		Fa[0][i]=fa[i];
	for(int i=1;i<18;i++)
		for(int j=1;j<=n;j++)
			Fa[i][j]=Fa[i-1][Fa[i-1][j]];
	ll last_ans=0;
	while(q--){
		ll x,l,r;
		read(x,l,r);
		l^=last_ans,r^=last_ans,x^=last_ans;
		int y=Range_lca(l,r);
		int z=lca(x,y);
		if(z!=y){
			write(last_ans=sum[x]+sum[y]-2ll*sum[z]),putch('\n');
		}else if(query(rt[r],1,n,dfn[x],dfn[x]+siz[x]-1,l)){
			write(last_ans=0),putch('\n'); 
		}else{
			ll ans=sum[x];
			for(int i=LOG[dep[x]];i>=0;i--){
				int X=Fa[i][x];
				if(!X)continue;
				if(!query(rt[r],1,n,dfn[X],dfn[X]+siz[X]-1,l))
					x=X;
			}
			x=fa[x];
			ans-=sum[x];
			write(last_ans=ans),putch('\n');
		}
	}
	return flush(),0;
}
